package com.alpha.eceasy.mall.controller;

import com.alpha.eceasy.core.R;
import com.alpha.eceasy.mall.api.dto.MallOrderDetailBidDTO;
import com.alpha.eceasy.mall.api.entity.MallOrderDetailBid;
import com.alpha.eceasy.mall.api.vo.MallOrderDetailBidVO;
import com.alpha.eceasy.mall.api.vo.MallOrderDetailVO;
import com.alpha.eceasy.mall.service.impl.MallOrderDetailBidServiceImpl;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 订单详情报价表（与订单详情表1对N） 前端控制器
 * </p>
 *
 * @author huangpengfei
 * @since 2024-04-24
 */
@RestController
@RequestMapping("/order-detail-bid")
@Tag(description = "order-detail-bid", name = "订单详情报价表")
public class MallOrderDetailBidController {
    @Resource
    private MallOrderDetailBidServiceImpl mallOrderDetailBidService;

    /**
     * 分页查询
     *
     * @param dto 需求采购订单详情报价
     * @return 分页结果
     */
    @Operation(description = "分页查询", summary = "分页查询")
    @GetMapping("")
    public R<IPage<MallOrderDetailBidVO>> page(
            @RequestParam(value = "pageNum", required = false, defaultValue = "1") Integer pageNumber,
            @RequestParam(value = "pageSize", required = false, defaultValue = "1000") Integer pageSize,
            MallOrderDetailBidDTO dto) {
        return R.ok(mallOrderDetailBidService.page(Page.of(pageNumber, pageSize), dto));
    }

    /**
     * 分页查询-根据Unicode聚合
     *
     * @param offererGuid unicode
     * @return 分页结果
     */
    @Operation(description = "分页查询-根据Unicode聚合", summary = "分页查询-根据Unicode聚合")
    @GetMapping("/unicode")
    public R<IPage<MallOrderDetailVO>> pageByUnicode(
            @RequestParam(value = "pageNum", required = false, defaultValue = "1") Integer pageNumber,
            @RequestParam(value = "pageSize", required = false, defaultValue = "1000") Integer pageSize,
            @RequestParam(value = "offererGuid", required = false) String offererGuid) {
        return R.ok(mallOrderDetailBidService.pageByUnicode(Page.of(pageNumber, pageSize), offererGuid));
    }

    /**
     * 通过guid查询需求采购订单详情报价详情
     *
     * @param guid guid
     * @return R 返回结果
     */
    @Operation(description = "通过guid查询需求采购订单详情报价详情", summary = "通过guid查询需求采购订单详情报价详情")
    @GetMapping("/{guid}")
    public R<MallOrderDetailBid> getByGuid(@PathVariable("guid") String guid) {
        return R.ok(mallOrderDetailBidService.getByGuid(guid));
    }

    /**
     * 通过unicode查询需求采购订单详情报价详情列表
     *
     * @param unicode unicode
     * @return R 返回结果
     */
    @Operation(description = "通过unicode查询需求采购订单详情报价详情列表", summary = "通过unicode查询需求采购订单详情报价详情列表")
    @GetMapping("/unicode/{unicode}")
    public R<List<MallOrderDetailBidVO>> listByUnicode(@PathVariable("unicode") String unicode) {
        return R.ok(mallOrderDetailBidService.listByUnicode(unicode));
    }

    /**
     * 通过guid删除需求采购订单详情报价
     *
     * @param guid guid
     * @return R 返回结果
     */
    //@SysLog("通过id删除需求采购订单详情报价")
    @Operation(description = "通过guid删除需求采购订单详情报价", summary = "通过guid删除需求采购订单详情报价")
    @DeleteMapping("/{guid}")
    public R<Boolean> removeById(@PathVariable String guid) {
        return R.ok(mallOrderDetailBidService.removeByGuid(guid));
    }

    /**
     * 新增需求采购订单详情报价
     *
     * @param dto 需求采购订单详情报价
     * @return R 返回结果
     */
    @Operation(description = "新增需求采购订单详情报价", summary = "新增需求采购订单详情报价")
    //@SysLog("新增需求采购订单详情报价")
    @PostMapping
    public R<Boolean> save(@RequestBody MallOrderDetailBidDTO dto) {
        return R.ok(mallOrderDetailBidService.saveDTO(dto));
    }

    /**
     * 修改需求采购订单详情报价
     *
     * @param mallOrderDetailBid 需求采购订单详情报价
     * @return R 返回结果 是否成功
     */
    @Operation(description = "通过guid修改需求采购订单详情报价", summary = "通过guid修改需求采购订单详情报价")
    //@SysLog("修改需求采购订单详情报价")
    @PutMapping
    public R<Boolean> updateByGuid(@RequestBody MallOrderDetailBid mallOrderDetailBid) {
        return R.ok(mallOrderDetailBidService.updateByGuid(mallOrderDetailBid));
    }
}
